<template>
    <div class="setOpenTime">
        
        <el-form :label-position="labelPosition" label-width="80px" :model="formInline">
            <el-form-item label="标题">
                <el-input v-model="formInline.title" placeholder="输入标题"></el-input>
            </el-form-item>
            <el-form-item label="身份">
                <el-select v-model="identity" placeholder="选择你要发送的对象">
                    <el-option label="老师" value="teacher"></el-option>
                    <el-option label="学生" value="student"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="内容">
                <el-input type="textarea" v-model="formInline.content"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">发送</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
      return {
        labelPosition: 'right',
        identity: '',
        formInline: {
          title: '',
          
          content: ''
        }
      }
    },
    methods: {
      onSubmit() {
        // 向后端接口发送信息
        console.log(123);
        if(this.identity === 'teacher'){
            axios.post(`/prod-api/message/sendAllTeacher`,this.formInline)
                .then(response =>{
                    console.log(response);
                    if(response.data.code === 0){
                        this.$message({
                            type: 'success',
                            message: '发送成功!'
                        });
                    }
                    
                }).catch(()=>{
                    this.$message({
                            type: 'success',
                            message: '发送失败!'
                        });
                })
        }else if(this.identity === 'student'){
            axios.post(`/prod-api/message/sendAllStudent`,this.formInline)
                .then(response =>{
                    if(response.data.code === 0){
                        this.$message({
                            type: 'success',
                            message: '发送成功!'
                        });
                    }
                }).catch(()=>{
                    this.$message({
                            type: 'success',
                            message: '发送失败!'
                        });
                })
        }
        
      }
    }
}
</script>

<style>
.setOpenTime{
    width: 50%;
    height: 50%;
    margin-top: 10%;
    margin-left: 20%;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>